//撞球

#include <stdio.h>
#include <math.h>
#include <string.h>

int main()
{
	//变量区
	double x0=0,y0=0;
	double x1=0,y1=0;
	double w=0,l=0;
	int turn=0;
	double distance=0;
	char direction[2000]={'\0'};
	
	//输入区
	scanf("%lf %lf",&w,&l);
	getchar();
	scanf("%lf %lf",&x0,&y0);
	getchar();
	scanf("%lf %lf",&x1,&y1);
	getchar();
	gets(direction);
	
	//计算区
	turn = strlen(direction);
	for( int i=0 ; i<turn ; i++ )
	{
		if ( direction[i] == 'F' )
		{
			x0 = x0;
			y0 = -y0;
		}
		else if( direction[i] == 'B' )
		{
			x0 = x0;
			y0 = 2*l-y0;
		}
		else if( direction[i] == 'L' )
		{
			x0 = -x0;
			y0 = y0;
		}
		else if( direction[i] == 'R' )
		{
			x0 = 2*w - x0;
			y0 = y0;
		}
	}
	distance = sqrt( (x1-x0) * (x1-x0) + (y1-y0) * (y1-y0) );
	
	//输出区
	printf("%.4lf\n",distance);
	
	return 0;
}